package cn.wolfcode.p2p.web.controller;

import cn.wolfcode.p2p.business.domain.BidRequest;
import cn.wolfcode.p2p.business.service.IBidRequestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

/**
 * 前台 首页
 */
@Controller
public class IndexController {
    @Autowired
    private IBidRequestService bidRequestService;

    // localhost默认直接跳转到首页
    @RequestMapping("/")
    public String index(Model model) {
        model.addAttribute("unPublishBidRequest", new ArrayList<>());
        List<BidRequest> bidRequests = bidRequestService.listIndexBidRequests(5);
        if (bidRequests != null) {
            model.addAttribute("bidRequests", bidRequests);
        } else {
            model.addAttribute("bidRequests", new ArrayList<>());
        }
        return "main";
    }

}
